<?php

namespace Analysis\Controller;

use Think\Controller;

class ApiController extends Controller
{

    /**
     * 短信平台返回数据
     */
    public function getSmsReturn()
    {
        $para = I("request.");
        if ($para["receiver"] != "getCulReturn" || $para["pswd"] != "cul00011") {
            echo "0,Auth Error.";
            exit;
        }

        echo $this->autoToAddSms($para);
    }

    /**
     * 短信平台数据入库
     */
    private function autoToAddSms($val)
    {
        $smscenter = M("smscenter");
        $data = array(
            "smc_user" => $val["mobile"],
            "smc_value" => $val["msg"],
            "smc_upmobile" => $val["destcode"],
            "smc_longtxt" => $val["isems"],
            "smc_arkshed" => $val["emshead"],
            "smc_time" => $val["moTime"]
        );

        if ($smscenter->add($data)) {
            $Applyext = D("Applyext");
            $status = $Applyext->getSalesInfo($val["msg"], $val["mobile"],$val["exp"]);
            return $status ? "1,Record Success." : "1,Record.";
        } else {
            return "0,System Error.";
        }
    }

    /**
     * 优惠券信息查询
     */
    public function getDiscInfo($code, $user = null)
    {
        $auth = D("Disc");
        $pollsize = M("pollsize");
        if ($pollsize->add(array("pol_uid"=>$user,"pol_cod"=>$code,"pol_time"=>time()))) {
            $info = $auth->infoTrans($code);
            echo $info;
        } else {
            echo json_encode(array("status"=>0,"alt"=>"系统错误","dis"=>null));
        }
    }

    /**
     * 优惠券使用记录
     */
    public function authDiscountCode()
    {
        $para = I("request.");
        $auth = D("Disc");
        echo $auth->checkCode($para);
    }
}
